﻿using System;
using ZX.Web.UI.Controls;
using ZX.SYS.Library;
using ZX.CRM.Bussiness;
using ZX.CRM.Library;
using ZX.DBModule;
using ZX.Common;
using System.Collections.Generic;
using ZX.BLL;
using ZX.EHR.Library;
using ZX.WebApp.CrmWorkFlowService;
using System.Data;
using System.Data.SqlClient;
using ZX.BLL.Extend;
namespace ZX.WebApp.Crm.Modules
{
    public partial class AddPay : EditUIPage
    {
        /// <summary>
        /// 产品列表信息
        /// </summary>
        protected string strListProduct { get; set; }
        /// <summary>
        /// 流程ID
        /// </summary>
        protected string strWorkFlowId { get; set; }
        /// <summary>
        /// 显示流程操作列表
        /// </summary>
        protected string strSpInfo { get; set; }
        /// <summary>
        /// 任务实例ID
        /// </summary>
        protected string strWorkTaskInsId { get; set; }
        /// <summary>
        /// 任务ID
        /// </summary>
        protected string strWorkTaskId { get; set; }
        /// <summary>
        /// 退回标志
        /// </summary>
        protected string strBack { get; set; }
        /// <summary>
        /// 直接缴款
        /// </summary>
        protected string strDirectPay { get; set; }
        /// <summary>
        /// 流程实例ID
        /// </summary>
        protected string strWorkFlowInsId { get; set; }
        /// <summary>
        /// 节点状态
        /// </summary>
        protected string strOperStatus { get; set; }
        protected string strPower { get; set; }
        protected int iFlow { get; set; }
        int tempIsValue = 0;
        BTCrmCustomer bTCrmCustomer = new BTCrmCustomer();
        BTCrmCrustomerOrder bTCrmCrustomerOrder = new BTCrmCrustomerOrder();
        BCrmPayFlow bCrmPayFlow = new BCrmPayFlow();
        BDatPhraseDetail bDatPhraseDetail = new BDatPhraseDetail();
        BaseUserControl baseuser = new BaseUserControl();
        string strOperatorInstanceId = "";
        //初始化服务实例
        WorkFlowServiceClient workFlowServiceClient = new WorkFlowServiceClient();
        int strAllPay;
        public string strWf
        {
            get;
            set;
        }
        public int StrAllPay
        {
            get { return strAllPay; }
            set { strAllPay = value; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                strAllPay = bTCrmCustomer.GetPrivateNum("IsAllowPay");//1.表示本次金额不能大于应收金额 其他则相反
                bindDro();
                this.FactPayDate.Value = DateTime.Now.ToString("yyyy-MM-dd");
                strDirectPay = this.GetStringFromQueryString("type", "");

                if (strDirectPay == "")
                {
                    btnQdnx.Visible = false;
                }
                //总部缴款

                //起草缴款单
                if (DataAction == "insert")
                {
                    if (strDirectPay == "")
                    {
                        State.SelectedIndex = 1;
                    }
                    else
                    {
                        State.SelectedIndex = 2;
                    }
                    //自增流水号
                    this.Code.Value = IDMaker.GetSequenceStr("BILL002");
                    this.ID.Value = Guid.NewGuid().ToString();
                    //缴款日期
                    this.Date.Value = DateTime.Now.ToString("yyyy-MM-dd");
                    this.TDeptId.Value = EmpPropertyValues.DeptID;
                    this.txtTDeptId.Value = EmpPropertyValues.DeptName;
                    //任务ID
                    strWorkTaskId = this.GetStringFromQueryString("wtid", "");
                    //流程ID
                    strWorkFlowId = this.GetStringFromQueryString("wfid", "");
                    //流程实例化ID
                    strWorkFlowInsId = Guid.NewGuid().ToString();
                    //任务实例化ID
                    strWorkTaskInsId = Guid.NewGuid().ToString();

                    WorkFlowId.Value = strWorkFlowId;
                    WorkTaskId.Value = strWorkTaskId;
                    WorkFlowInsId.Value = strWorkFlowInsId;
                    WorkTaskInsId.Value = strWorkTaskInsId;
                    //订单页面跳转过来 的起草缴款单
                    string strOrderId = this.GetStringFromQueryString("OrderId", "");
                    if (this.GetStringFromQueryString("OrderId", "") != "")
                    {
                        V_CrmCustomerOrder vcco = new V_CrmCustomerOrder();
                        vcco = bTCrmCrustomerOrder.GetAllCrmCustomerOrder(new Guid(strOrderId));
                        if (vcco != null)
                        {
                            this.ID.Value = vcco.CustomerId.ToString();
                            this.OrderCode.Value = vcco.CustomerId.ToString();
                            txtOrderCode.Value = getCode(vcco.CustomerId);
                            ValutaID.SelectedValue = vcco.ValutaID.ToString();
                            DeptId.Value = vcco.DeptId.ToString();
                            DatDepartment ddt = bTCrmCustomer.GetDatDepartInfo(vcco.DeptId);
                            if (ddt != null)
                            {
                                txtDeptId.Value = ddt.DeptName;
                            }
                            PillID.SelectedValue = vcco.PillID.ToString();
                            State.SelectedValue = vcco.StateID.ToString();
                        }
                    }
                }
                else { this.ID.Value = this.GetStringFromQueryString("id", ""); Update(this.GetStringFromQueryString("id", "")); }

            }
            strWorkFlowId = this.GetStringFromQueryString("WorkflowId", "");
            if (strWorkFlowId != "")
            {
                strWorkTaskInsId = this.GetStringFromQueryString("WorktaskInsId", "");
                strWorkTaskId = this.GetStringFromQueryString("WorktaskId", "");
                strWorkFlowInsId = this.GetStringFromQueryString("WorkflowInsId", "");
                WorkFlowId.Value = strWorkFlowId;
                WorkTaskId.Value = strWorkTaskId;
                WorkFlowInsId.Value = strWorkFlowInsId;
                WorkTaskInsId.Value = strWorkTaskInsId;
                if (this.GetStringFromQueryString("view", "") != "")
                {
                    strBack = this.GetStringFromQueryString("view", "");
                    if (strBack == "check")
                    {
                        btnAccept.Visible = true;
                        btnDone.Visible = false;
                    }
                }
                strOperStatus = this.GetStringFromQueryString("OperStatus", "");
                DataTable dt = workFlowServiceClient.GetAuditMsgTableByFlow(strWorkFlowInsId);

                if (dt != null && dt.Rows.Count > 0)
                {
                    strSpInfo = "1";
                    rptCheckInfo.DataSource = dt;
                    rptCheckInfo.DataBind();
                }
                else
                {
                    baseuser.CtrlState = WorkFlowConst.STATE_ADD;
                }
                DataTable dts = workFlowServiceClient.GetTaskPowers(strWorkTaskId);
                foreach (DataRow dr in dts.Rows)
                {
                    strPower = strPower + dr["PowerName"].ToString() + ",";
                }
                strOperatorInstanceId = this.GetStringFromQueryString("OperatorInstanceId", "");
                lbUserId.Text = this.User.LoginName;
                lbUserName.Text = this.User.UName;
                lbAuditTime.Text = DateTime.Now.ToLongDateString();

                Bind(strWorkFlowInsId);
                if (State.SelectedIndex == 2)
                {
                    rbtNo.Visible = false;
                }
            }
            if (this.GetStringFromQueryString("WorkflowInsId", "") != "")
            {
                strWf = this.GetStringFromQueryString("WorkflowInsId", "");
                Inits(strWf);
            }
        }
        /// <summary>
        /// 初始化流程列表
        /// </summary>
        /// <param name="workflowInsId"></param>
        public void Inits(string wf)
        {
            DataTable dt = workFlowServiceClient.GetWorkflowdetail(wf);
            //if (dt == null || dt.Rows.Count == 0)
            //{
            //    gvworkflowMessage.Visible = false;
            //}
            //else
            //{
            gvworkflowMessage.DataSource = dt;
            gvworkflowMessage.DataBind();
            //}
        }
        /// <summary>
        /// 下拉框绑定
        /// </summary>
        private void bindDro()
        {

            IList<DatPhraseDetail> ListValuteId = bDatPhraseDetail.GetDatPhraseDetailByClassValue("ValuteID");
            if (ListValuteId != null && ListValuteId.Count > 0)
            {
                this.ValutaID.DataSource = ListValuteId;
                this.ValutaID.DataTextField = "PhraseText";
                this.ValutaID.DataValueField = "PhraseID";
                this.ValutaID.DataBind();
            }
            IList<DatPhraseDetail> ListStateId = bDatPhraseDetail.GetDatPhraseDetailByClassValue("PayState");
            if (ListStateId != null && ListStateId.Count > 0)
            {
                this.State.DataSource = ListStateId;
                this.State.DataTextField = "PhraseText";
                this.State.DataValueField = "PhraseID";
                this.State.DataBind();
            }
            IList<DatPhraseDetail> ListAccount = bDatPhraseDetail.GetDatPhraseDetailByClassValue("AccountFrom");
            if (ListAccount != null && ListAccount.Count > 0)
            {
                this.ddlAccount.DataSource = ListAccount;
                this.ddlAccount.DataTextField = "PhraseText";
                this.ddlAccount.DataValueField = "PhraseID";
                this.ddlAccount.DataBind();
            }
        }
        #region 流程操作事件
        /// <summary>
        /// 知道了
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAccept_Click(object sender, EventArgs e)
        {
            string msg1 = workFlowServiceClient.Run(this.User.LoginName, strOperatorInstanceId, "提交");
            Response.Redirect("../BasePages/tooltip.aspx?worktaskInstanceId=" + strWorkTaskInsId);
        }
        /// <summary>
        /// 放弃
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDrop_Click(object sender, EventArgs e)
        {
            workFlowServiceClient.TaskUnClaim(this.User.LoginName, strOperatorInstanceId);
            btnAccept.Enabled = true;
            btnDrop.Enabled = false;
            btnReturn.Enabled = false;
            btnDone.Enabled = false;
        }
        /// <summary>
        /// 退回
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnReturn_Click(object sender, EventArgs e)
        {
            workFlowServiceClient.TaskBack(this.User.LoginName, strOperatorInstanceId);
            Response.Redirect("../BasePages/tooltip.aspx?worktaskInstanceId=" + strWorkTaskInsId);
        }
        /// <summary>
        /// 提交
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDone_Click(object sender, EventArgs e)
        {
            workFlowServiceClient.TaskClaim(this.User.LoginName, strOperatorInstanceId);
            //保存插入和更新操作    
            CrmWorkFlowService.AuditMessage am = new CrmWorkFlowService.AuditMessage();
            am.AuditId = Guid.NewGuid().ToString();
            am.WorkflowId = strWorkFlowId;
            am.WorkflowInsId = strWorkFlowInsId;
            am.WorktaskId = strWorkTaskId;
            am.WorktaskInsId = strWorkTaskInsId;
            am.OperatorInsId = strOperatorInstanceId;
            am.AuditUserId = lbUserId.Text;
            am.AuditUserName = lbUserName.Text;
            am.AuditArch = lbArch.Text;
            am.AuditDuty = lbDuty.Text;
            //am.AuditTime


            if (pCheck.Value == "no")
            { am.AuditResult = "拒绝"; }
            else { am.AuditResult = "同意"; }

            am.Message = hdnMessage.Value;

            BaseBussnies bli = new BaseBussnies();
            bli.RunSqlCommand("update CrmPay set EXP1='" + hdnSelectValue.Value + "' where WorkFlowInsId='" + strWorkFlowInsId + "'");

            //if (baseuser.CtrlState == WorkFlowConst.STATE_ADD)
            //{
            //这里换成接口
            //}
            //else
            //{
            //    if (baseuser.CtrlState == WorkFlowConst.STATE_MOD)
            //        workFlowServiceClient.UpdateAuditMessage(am);  //这里换成接口 
            //}

            //if (iFlow > -1 && CustomId.Value != "")//允许退回
            //{
            //    BUser bUser = new BUser();
            //    DatUser dus= bUser.GetDatUserByUserId(new Guid(CustomId.Value));
            //    workFlowServiceClient.WorkTaskAssign(this.User.LoginName, dus.LoginName, strOperatorInstanceId);
            //    Response.Write("<script>alert('指派成功！');Close();</script>");
            //} else{
            //BaseBussnies bli = new BaseBussnies();
            //CrmPay cct = new CrmPay();
            //bli = new BaseBussnies(cct);
            //bli.RunSqlCommand("update CrmPay set InvoiceNum='" + CSVHelper.FmSQL(InvoiceNum.Value) + "',FactPayDate='" + CSVHelper.FmSQL(FactPayDate.Value) + "',Receipt='" + Receipt.Value + "' where ID=''");
            //}   
            if (pCheck.Value == "no")
            {
                bli.RunSqlCommand("update CrmPay set State='D0FFAC61-BA7A-4850-951C-F7E269694BD3' where WorkFlowInsId='" + strWorkFlowInsId + "'");
                workFlowServiceClient.InsertAuditMessage(am);
                workFlowServiceClient.TaskBackApplicant(this.User.LoginName, strOperatorInstanceId);
                Response.Redirect("../BasePages/tooltip.aspx?worktaskInstanceId=" + strWorkTaskInsId);
            }
            else
            {
                //if (IsPerformance.SelectedValue != "0" && tempIsValue == 0)
                State.SelectedIndex = 2;
                CrmPay instance = new CrmPay();
                IDataParameter[] _Parameters = new IDataParameter[] { };
                SqlParameter spSatate = new SqlParameter("@State", SqlDbType.UniqueIdentifier, 50);
                spSatate.Direction = ParameterDirection.Input;
                spSatate.Value = new Guid(State.SelectedValue);
                SqlParameter spInvoiceNum = new SqlParameter("@InvoiceNum", SqlDbType.NVarChar, 50);
                spInvoiceNum.Direction = ParameterDirection.Input;
                spInvoiceNum.Value = pInvoiceNum.Value;
                //SqlParameter EXP1 = new SqlParameter("@EXP1", SqlDbType.NVarChar, 50);
                //EXP1.Direction = ParameterDirection.Input;
                //EXP1.Value = instance.EXP1;
                //SqlParameter EXP2 = new SqlParameter("@EXP2", SqlDbType.NVarChar, 50);
                //EXP2.Direction = ParameterDirection.Input;
                //EXP2.Value = instance.EXP2;
                //SqlParameter EXP3 = new SqlParameter("@EXP3", SqlDbType.NVarChar, 50);
                //EXP3.Direction = ParameterDirection.Input;
                //EXP3.Value = instance.EXP3;
                SqlParameter spFactPayDate = new SqlParameter("@FactPayDate", SqlDbType.DateTime, 50);
                spFactPayDate.Direction = ParameterDirection.Input;
                spFactPayDate.Value = DateTime.Parse(pFactPayDate.Value);
                SqlParameter spReceipt = new SqlParameter("@Receipt", SqlDbType.NVarChar, 50);
                spReceipt.Direction = ParameterDirection.Input;
                spReceipt.Value = pReceipt.Value;
                SqlParameter spPid = new SqlParameter("@PID", SqlDbType.UniqueIdentifier, 50);
                spPid.Direction = ParameterDirection.Input;
                spPid.Value = new Guid(this.ID.Value);
                SqlParameter ProduectList = new SqlParameter("@ProduectList", SqlDbType.NVarChar, 4000);
                ProduectList.Direction = ParameterDirection.Input;
                ProduectList.Value = pValue.Value;
                SqlParameter addUser = new SqlParameter("@Adduser", SqlDbType.UniqueIdentifier, 50);
                addUser.Direction = ParameterDirection.Input;
                addUser.Value = this.UserId;

                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;
                _Parameters = new IDataParameter[] { spSatate, spInvoiceNum, spFactPayDate, spReceipt, spPid, ProduectList, addUser, ReturnValue };
                string strSql = bTCrmCustomer.UpdateCrmPay("sp_EditCrmPay", _Parameters);
                if (strSql == "1")
                {
                    workFlowServiceClient.InsertAuditMessage(am);
                    string msg1 = workFlowServiceClient.Run(this.User.LoginName, strOperatorInstanceId, "提交");
                    Response.Redirect("../BasePages/tooltip.aspx?worktaskInstanceId=" + strWorkTaskInsId);
                }
            }
        }
        #endregion
        #region 属性赋值
        private string getCode(Guid gd)
        {
            return "";
            //return (bTCrmCustomer.GetAllCustomerInfo(gd) == null || bTCrmCustomer.GetAllCustomerInfo(gd).Count == 0) ? "" : bTCrmCustomer.GetAllCustomerInfo(gd)[0].Code;
        }
        public string getTaskInsId
        {
            get { return strWorkTaskInsId; }
        }
        /// <summary>
        /// 弹出列表客户经理ID
        /// </summary>
        public string addUser
        {
            get { return this.UserId.ToString(); }
        }
        public string getTitle
        { get { return this.GetStringFromQueryString("title", ""); } }
        public string Flag
        { get { return this.GetStringFromQueryString("flag", ""); } }
        public string ListCrmProduct { get { return strListProduct; } }
        private string GetListCrmProduct()
        {
            IList<V_CrmProductPay> list = bTCrmCrustomerOrder.GetAllCrmProductPayByCid(new Guid(this.ID.Value));
            if (list != null && list.Count > 0)
            {
                return ZX.Common.Globals.ObjectToJSON(list);
            }
            else
            {
                return "";
            }

        }

        private string GetListPayType()
        {
            IList<DatPhraseDetail> list = bDatPhraseDetail.GetDatPhraseDetailByClassValue("PaymentID");
            if (list != null && list.Count > 0)
            {
                return ZX.Common.Globals.ObjectToJSON(list);
            }
            else
            {
                return "";
            }
        }
        /// <summary>
        /// 历史数据录入
        /// </summary>
        /// <returns></returns>
        public string GetHistory
        {
            get { return this.GetStringFromQueryString("history", ""); }
        }
        private string GetListAccount()
        {
            IList<DatPhraseDetail> list = bDatPhraseDetail.GetDatPhraseDetailByClassValue("BankAccount");
            if (list != null && list.Count > 0)
            {
                return ZX.Common.Globals.ObjectToJSON(list);
            }
            else
            {
                return "";
            }
        }
        public string ListRecord
        { get { return GetListCrmProduct(); } }
        public string ListPayType
        {
            get { return GetListPayType(); }
        }
        /// <summary>
        /// 银行账号
        /// </summary>
        public string ListAccount
        {
            get { return GetListAccount(); }
        }
        #endregion
        /// <summary>
        /// 更新，查看信息
        /// </summary>
        /// <param name="strId">缴款单ID</param>
        private void Update(string strId)
        {
            IList<V_CrmTempPay> listLinkRecord = bTCrmCustomer.GetAllListPay(new Guid(strId));
            if (listLinkRecord != null && listLinkRecord.Count > 0)
            {
                IList<BaseEntity> _listLinkRecord = new List<BaseEntity>();
                foreach (var _e in listLinkRecord)
                {
                    _listLinkRecord.Add(_e);
                }
                strListProduct = _listLinkRecord.ToJSON().Replace("\n", "").Replace("\r", "").Replace("@@", "");
            }
            CrmPay clm = bTCrmCustomer.GetCrmPayInfo(new Guid(strId));
            if (clm != null)
            {
                btnOrderCode.Visible = false;
                ID.Value = clm.ID.ToString();
                Code.Value = clm.Code;
                V_CrmCustomerInfo vc = bTCrmCustomer.GetV_CrmCustomerInfo(clm.CustomerId);
                if (vc != null)
                {
                    txtOrderCode.Value = vc.Code;
                    CustomerName.Value = vc.CustomerName;
                    CustomerType.Value = vc.TypeName;
                    LectorName.Value = vc.LectorName;
                    AddUserName.Value = vc.AddUserName;
                    SaleadName.Value = vc.SaleadviserName;
                    txtJName.Value = vc.CustomerMgrName;
                    JName.Value = vc.CustomeerMgr.ToString();
                }
                CustomId.Value =getLoginName(clm.CheckUser);
                ddlIsCEOInnerTrain.SelectedValue = clm.IsCEOInnerTrain;
                ddlIsFifteenMonth.SelectedValue = clm.IsFifteenMonth;
                ddlIsFisrtSale.SelectedValue = clm.IsFisrtSale;
                ddlIsInnerTrainSian.SelectedValue = clm.IsInnerTrainSian;
                ddlIsProjectOver.SelectedValue = clm.IsProjectOver;
                ddlAccount.SelectedValue = clm.AccountFrom.ToString();
                txtActionUser.Value = clm.EXP3;
                hdnActionUser.Value = clm.EXP2;
                OrderCode.Value = clm.CustomerId.ToString();
                // PayType.SelectedValue = clm.PayType.ToString();
                ValutaID.SelectedValue = clm.ValutaID.ToString();
                DeptId.Value = clm.DeptId.ToString();
                DatDepartment ddt = bTCrmCustomer.GetDatDepartInfo(clm.DeptId);
                if (ddt != null)
                {
                    txtDeptId.Value = ddt.DeptName;
                }
                PayDate.Value = (clm.PayDate.ToString("yyyy-MM-dd") == "0001-01-01" || clm.PayDate.ToString("yyyy-MM-dd") == "1900-01-01") ? "" : clm.PayDate.ToString("yyyy-MM-dd");
                PillID.SelectedValue = clm.PillID.ToString();
                InvoiceNum.Value = clm.InvoiceNum;
                FactPayDate.Value = (clm.FactPayDate.ToString("yyyy-MM-dd") == "0001-01-01" || clm.FactPayDate.ToString("yyyy-MM-dd") == "1900-01-01") ? "" : clm.FactPayDate.ToString("yyyy-MM-dd");
                Receipt.Value = clm.Receipt;
                if (Receipt.Value != "" && strDirectPay == "")
                {
                    InvoiceNum.Disabled = true;
                    FactPayDate.Disabled = true;
                    Receipt.Disabled = true;
                }
                FName.Value = clm.FZName.ToString();
                ZName.Value = clm.CZName.ToString();
                TDeptId.Value = clm.CTeam.ToString();
                JName.Value = clm.CJName.ToString();
                ddlIsYj.SelectedValue = clm.IsYj;
                BankDate.Value = clm.BankDate < DateTime.Now.AddYears(-50) ? "" : clm.BankDate.ToString("yyyy-MM-dd");
                txtZName.Value = getUName(clm.CZName);
                txtFName.Value = getUName(clm.FZName);
                txtJName.Value = getUName(clm.CJName);
                txtPayAddress.Value = clm.PayAddress;
                DatDepartment tddt = bTCrmCustomer.GetDatDepartInfo(clm.CTeam);
                if (tddt != null)
                {
                    txtTDeptId.Value = tddt.DeptName;
                }
                State.SelectedValue = clm.State.ToString();
                Date.Value = (clm.Date.ToString("yyyy-MM-dd") == "0001-01-01" || clm.Date.ToString("yyyy-MM-dd") == "0001-01-01") ? "" : clm.Date.ToString("yyyy-MM-dd");
                Explain.Value = clm.Explain;
                IsPerformance.SelectedValue = clm.EXP1 == "" ? "0" : clm.EXP1;
                tempIsValue = (clm.FactPayDate.ToString("yyyy-MM-dd") == "0001-01-01" || clm.FactPayDate.ToString("yyyy-MM-dd") == "1900-01-01") ? 0 : 1;
            }
        }
        /// <summary>
        /// 获取用户名
        /// </summary>
        /// <param name="gd">用户ID</param>
        /// <returns></returns>
        private string getUName(Guid? gd)
        {
            BVuseremp bVuseremp = new BVuseremp();
            DatUser datUser = bVuseremp.getDatUserByUserId(gd);
            return datUser == null ? "" : datUser.UName;
        }
        /// <summary>
        /// 获取用户ID
        /// </summary>
        /// <param name="loginName">用户名</param>
        /// <returns></returns>
        private string getLoginName(string loginName)
        {
            BUser bVuseremp = new BUser();
            DatUser datUser = bVuseremp.GetDatUserByName(loginName);
            return datUser == null ? "" : datUser.UserID.ToString();
        }
        /// <summary>
        /// 查看
        /// </summary>
        /// <param name="cpid"></param>
        private void Bind(string cpid)
        {
            V_CrmPay vcp = bCrmPayFlow.GetCrmPayInfoById(cpid == "" ? Guid.NewGuid() : new Guid(cpid));
            if (vcp != null)
            {
                //PayType.Enabled = false;
                if (strBack != "unDone")
                {
                    PayDate.Disabled = true;
                    ValutaID.Enabled = false;
                    PillID.Enabled = false;
                    State.Enabled = false;
                    Explain.Disabled = true;
                    txtPayAddress.Disabled = true;
                    txtDeptId.Disabled = true;
                    //IsPerformance.Enabled = false;
                    btnDeptId.Visible = false;
                    btnTDeptId.Visible = false;
                    txtTDeptId.Disabled = true;
                    btnZName.Visible = false;
                    txtZName.Disabled = true;
                    btnJName.Visible = false;
                    txtJName.Disabled = true;
                    btnFName.Visible = false;
                    txtFName.Disabled = true;

                    this.OrderCode.Value = vcp.CustomerId.ToString();
                    txtOrderCode.Value = getCode(vcp.CustomerId);
                }
                Update(vcp.ID.ToString());
            }
        }
        public string strDescript
        { get { return this.GetStringFromQueryString("descript", ""); } }
        public string strTitle
        {
            get { return this.GetStringFromQueryString("title", ""); }
        }
        public string LocalDate
        { get { return DateTime.Now.ToString("yyyy-MM-dd"); } }
    }
}